package com.winkyle.woodenfish.presenter;


import com.winkyle.woodenfish.controller.fragment.MessageFragment;
import com.winkyle.woodenfish.entity.HttpResult;
import com.winkyle.woodenfish.entity.MessageInfo;
import com.winkyle.woodenfish.mvpview.MessageView;
import com.winkyle.woodenfish.retrofit.MessageInfoRetrofit;
import com.winkyle.woodenfish.rx.HttpSubscriber;

import java.util.List;

/**
 * @author winkyle
 * @date 2018/06/20
 * @description  碎片类 {@link MessageFragment}的p层
 */

public class MessagePresenter extends BaseMvpPresenter<MessageView>{
    /**
     * @description 向服务器请求我的消息信息，若请求成功
     *               则调用v层刷新消息方法，若失败则弹出Toast，告知原因
     * @param page 请求的消息页数
     * @return
     */
    public void viewMessage(Integer page){
        subscribeToRequest(createRetrofitApi(MessageInfoRetrofit.class).findMessageInfoByUserId(page),
                new HttpSubscriber<MessagePresenter,HttpResult<List<MessageInfo>>>(this) {
                    @Override
                    public void processData(HttpResult<List<MessageInfo>> httpResult) {
                        if(httpResult.getCode() == 1){
                            getMvpView().refreshMessage(httpResult.getBody());
                            return;
                        }
//                        getMvpView().showShortToast(httpResult.getMsg());
                    }
                });

    }
}
